<%--
  Created by IntelliJ IDEA.
  User: 飞蓬
  Date: 2018/4/26
  Time: 21:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <jsp:include page="../js_top.jsp"/>
    <link href="<%=basePath%>/static/css/css.css" rel="stylesheet" type="text/css"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="userList">

    <style type="text/css">
        .table_report {
            width: 540px;
            margin: 15px auto;
        }

        .table_report tr td {
            line-height: 31px;
            color: #63666d;
            font-size: 14px;
            font-family: Arial, Helvetica, "微软雅黑";
        }

        .table_report tr td a {
            width: 185px;
            height: 38px;
            line-height: 38px;
            -webkit-border-radius: 5px;
            border-radius: 5px;
            border-color: #b7bacb;
            display: block;
            font-size: 14px;
            font-family: "微软雅黑";
            text-shadow: 0 0px 0 rgba(0, 0, 0, 0) !important;
            background: #b7bacb url(/static/img/images/table_report_icon1.png) no-repeat 70px center;
            text-align: center;
            color: #fff;
            cursor: pointer;
            text-indent: 20px;
            float: left;
            margin: 0 20px 0 0;
        }

        .table_report tr td a:hover, .table_report tr:last-child td:last-child a:hover {
            background-color: #0fb1d6;
            text-decoration: none;
        }

        input:focus:invalid:focus, textarea:focus:invalid:focus, select:focus:invalid:focus {
            border-color: #f59942;
        }
    </style>
</head>
<body>


<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <table class="table  table-striped table-hover table_report">

                <tr style="margin-top: 20px">
                    <span>医院名称：</span>
                    <select class="form-control" id="hospitalselect" onchange="getDpByhs()">
                        <c:forEach var="hs" items="${hospital}">
                            <option value="${hs.id}">${hs.name}</option>
                        </c:forEach>
                    </select>
                </tr>
                <tr>
                    <span>科室名称：</span>
                    <select class="form-control" id="departmentselect" onchange="getDcByBelongedid()">
                    </select>
                </tr>
                <tr>
                    <span>医生名称：</span>
                    <select class="form-control" id="doctorselect" onchange="getDateByDoctor()">
                    </select>
                </tr>
                <tr>
                    <span>预约就诊日期：</span>
                    <select class="form-control" id="dateselect" onchange="getTimesByDate()">
                    </select>
                </tr>
                <tr>
                    <span>预约就诊时间段：</span>
                    <select class="form-control" id="timesselect">
                    </select>
                </tr>
                <c:if test="${isfront == '1'}">
                    <tr>
                        <span>模拟现场挂号用户人数：</span>
                        <input type="text" class="form-control" name="imitatepeople" id="imitatepeople"  placeholder="请填写模拟现场挂号用户人数。。。。。。" />
                    </tr>
                </c:if>
                <tr>
                    <c:if test="${isfront == '1'}">
                        <td colspan="5">
                            <a  style="margin-left: 160px"  href="javascript:preOrder();">预挂号</a>
                        </td>
                    </c:if>
                    <c:if test="${isfront != '1'}">
                        <td colspan="10">
                        <a style="margin-left: 66px" href="javascript:save();">确定</a>
                        <a href="javascript:top.Dialog.close();">取消</a>
                        </td>
                    </c:if>
                </tr>
            </table>
        </div>

    </div>
</div>
</body>


<script type="text/javascript">
    //鼠标点过高亮取到相关数据
    $(function () {

        if("${isupdate}" == "1"){
            $("#hospitalselect").val("${orderupdate.hospitalid}");
            getDpByhs();
            $("#departmentselect").val("${orderupdate.departmentid}");
            getDcByBelongedid();
            $("#doctorselect").val("${orderupdate.userId}");
            getDateByDoctor();
            $("#dateselect").val("${orderupdate.visitdate}");
            getTimesByDate();
        }else{
            getDpByhs();
        }

    });
    //动态获取科室列表
    function getDpByhs() {
        var hospitalid = $("#hospitalselect option:selected").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: '<%=basePath%>hs/hospital/getDpByhs.do',
            data: {"id":hospitalid},
            async: false,
            error: function (request) {
                layer.msg('<span style="color:white;">获取科室列表出错 !</span>');
            },
            success: function (data) {
                if(data){
                    var json = eval("("+data+")");
                    $("#departmentselect").empty();
                    $.each(json,function(i,item){

                        $("#departmentselect").append("<option value="+item.departmentid+">"+item.departmentname+"</option>");
                    });
                    getDcByBelongedid();
                }
            }

        });
    }
    //动态获取医生列表
    function getDcByBelongedid() {
        var hospitalid = $("#hospitalselect option:selected").val();
        var departmentid = $("#departmentselect option:selected").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: '<%=basePath%>hs/order/getDcByBelongedid.do',
            data: {"hospitalid":hospitalid, "departmentid": departmentid},
            async: false,
            error: function (request) {
                layer.msg('<span style="color:white;">获取医生列表出错 !</span>');
            },
            success: function (data) {
                if(data){
                    var json = eval("("+data+")");
                    $("#doctorselect").empty();
                    $.each(json,function(i,item){

                        $("#doctorselect").append("<option value="+item.doctorid+">"+item.doctorname+"</option>");
                    });
                    getDateByDoctor();
                }
            }

        });
    }
    //动态获取预约日期
    function getDateByDoctor() {
        var doctorid = $("#doctorselect option:selected").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: '<%=basePath%>hs/order/getDateByDoctor.do',
            data: {"doctorid":doctorid},
            async: false,
            error: function (request) {
                layer.msg('<span style="color:white;">获取日期列表出错 !</span>');
            },
            success: function (data) {
                if(data){
                    var json = eval("("+data+")");
                    $("#dateselect").empty();
                    $.each(json,function(i,item){

                        $("#dateselect").append("<option value="+item.visitdate+">"+item.visitdate+"</option>");
                    });
                    getTimesByDate();
                }
            }

        });

    }
    //根据医生和预约日期获取预约时间段
    function getTimesByDate() {
        var doctorid = $("#doctorselect option:selected").val();
        var visitdate = $("#dateselect option:selected").val();

        $.ajax({
            cache: true,
            type: "POST",
            url: '<%=basePath%>hs/order/getTimesByDate.do',
            data: {"doctorid":doctorid,"visitdate":visitdate},
            async: false,
            error: function (request) {
                layer.msg('<span style="color:white;">获取时间段列表出错 !</span>');
            },
            success: function (data) {
                if(data){
                    var json = eval("("+data+")");
                    $("#timesselect").empty();
                    $.each(json,function(i,item){

                        $("#timesselect").append("<option value="+item.id+">"+item.visitstarttime+"~"+item.visitendtime+"(可预约人数"+item.visitquato+"人)"+"</option>");
                    });

                }
            }

        });
    }

    function save() {
        var userId = "${order.userId}";
        var timelineid = $("#timesselect option:selected").val();
        var id = "";
        var oldtimelineId = "${orderupdate.timelineId}";
        if("${isupdate}" == "1"){
            id = "${orderupdate.id}";
        }
        if(timelineid == "" || timelineid == null){
            layer.msg('请选择预约时间段！！');
            return false;
        }
        $.ajax({
            cache: true,
            type: "POST",
            url: '<%=basePath%>hs/order/save.do',
            data: {"userId":userId, "timelineId": timelineid,"id":id,"oldtimelineId":oldtimelineId},
            async: false,
            error: function (request) {
                layer.msg('<span style="color:white;">挂号出错 !</span>');
            },
            success: function (data) {
                if (data = true) {
                    top.Dialog.close();
                } else {
                    layer.msg('<span style="color:white;">挂号出错 !</span>');
                }
            }
        });

    }
    
    function preOrder() {
        var doctorid = $("#doctorselect option:selected").val();
        var timelineid = $("#timesselect option:selected").val();
        var imitatepeople = $("#imitatepeople").val();
        if(timelineid == "" || timelineid == null){
            layer.msg('请选择预约时间段！！');
            return false;
        }
        if(imitatepeople == "" || imitatepeople == null){
            layer.msg('请输入模拟现场挂号人数！！');
            return false;
        }
        var diag = new top.Dialog();
        diag.Title="预挂号";
        diag.URL='<%=basePath%>hs/order/preOrder.do?doctorid='+doctorid+'&timelineId='+timelineid+'&imitatepeople='+imitatepeople;//跳转页面函数
        diag.Top="50%";
        diag.Left="30%";
        diag.Width=580;
        diag.Height=330;
        diag.CancelEvent=function(){
            diag.close();
        };
        diag.show();

    }

</script>
</html>
